package com.hakim.wfb.admin.filter;

import com.hakim.wfb.admin.enums.ErrorCodeEnum;
import com.hakim.wfb.bean.Admin;
import com.hakim.wfb.dao.AdminDao;
import com.hkfs.fundamental.api.data.ResultEx;
import com.hkfs.fundamental.validate.ValidateFilter;
import com.hkfs.fundamental.validate.annotaion.ValidateFilterBean;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;

/**
 *
 */
@ValidateFilterBean
public class DeleteRoleFilter extends ValidateFilter<DeleteRoleFilter.DeleteRoleFilterParam> {

    @Autowired
    AdminDao userDao;

    @Override
    protected void prcoess(DeleteRoleFilterParam param, ResultEx resultEx){
        Admin queryParam = new Admin();
        queryParam.setRoleId(param.getRoleId());
        int count = userDao.count(queryParam);
        if(count > 0){
            resultEx.makeResult(ErrorCodeEnum.ROLE_IN_USE.getCode(), ErrorCodeEnum.ROLE_IN_USE.getMessage());
            return;
        }
        resultEx.makeSuccessResult();
    }
    public static class DeleteRoleFilterParam{
        @NotNull(message = "角色ID不能为空")
        private Long roleId;

        public Long getRoleId() {
            return roleId;
        }

        public void setRoleId(Long id) {
            this.roleId = id;
        }
    }
}
